options compress=YES;
libname manasi ''; 
libname f831 ''; 

proc sort data=manasi.par_831_hunmerge out=manasi.par_831_hunmerge;
	by hun;
run;

data manasi.par_831_hunmerge_wide;
	set manasi.par_831_hunmerge;
	par_id + 1;
	by hun;
	if first.hun then par_id=1;
run;

data manasi.par_831_hunmerge_wide;
	set manasi.par_831_hunmerge_wide;
	if ssn='*00000000' then delete;
run;

proc means data=manasi.par_831_hunmerge_wide noprint;
	by hun;
	var par_id;
	output out=manasi.par_831_parid max(par_id)=max_parid;
run;

proc means mean median min max p90 p95 p99 data=manasi.par_831_parid;
	var max_parid;
run;

* COLLAPSE TO HUN LEVEL TO GET ONE RECORD FOR EACH KID;
data manasi.par_831_hunmerge_wide;
	set manasi.par_831_hunmerge_wide;
	by hun;

	keep 	hun 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7

			inhh0206_1-inhh0206_7
			n_par831_diself_1985_1-n_par831_diself_1985_7
			n_par831_diself_1986_1-n_par831_diself_1986_7
			n_par831_diself_1987_1-n_par831_diself_1987_7
			n_par831_diself_1988_1-n_par831_diself_1988_7
			n_par831_diself_1989_1-n_par831_diself_1989_7
			n_par831_diself_1990_1-n_par831_diself_1990_7
			n_par831_diself_1991_1-n_par831_diself_1991_7
			n_par831_diself_1992_1-n_par831_diself_1992_7
			n_par831_diself_1993_1-n_par831_diself_1993_7
			n_par831_diself_1994_1-n_par831_diself_1994_7
			n_par831_diself_1995_1-n_par831_diself_1995_7
			n_par831_diself_1996_1-n_par831_diself_1996_7
			n_par831_diself_1997_1-n_par831_diself_1997_7
			n_par831_diself_1998_1-n_par831_diself_1998_7
			n_par831_diself_1999_1-n_par831_diself_1999_7
			n_par831_diself_2000_1-n_par831_diself_2000_7
			n_par831_diself_2001_1-n_par831_diself_2001_7
			n_par831_diself_2002_1-n_par831_diself_2002_7
			n_par831_diself_2003_1-n_par831_diself_2003_7
			n_par831_diself_2004_1-n_par831_diself_2004_7
			n_par831_diself_2005_1-n_par831_diself_2005_7
			n_par831_diself_2006_1-n_par831_diself_2006_7
			n_par831_diself_2007_1-n_par831_diself_2007_7
			n_par831_diself_2008_1-n_par831_diself_2008_7
			n_par831_diself_2009_1-n_par831_diself_2009_7
			n_par831_diself_2010_1-n_par831_diself_2010_7
			n_par831_diself_2011_1-n_par831_diself_2011_7

			n_par831_ssiself_1985_1-n_par831_ssiself_1985_7
			n_par831_ssiself_1986_1-n_par831_ssiself_1986_7
			n_par831_ssiself_1987_1-n_par831_ssiself_1987_7
			n_par831_ssiself_1988_1-n_par831_ssiself_1988_7
			n_par831_ssiself_1989_1-n_par831_ssiself_1989_7
			n_par831_ssiself_1990_1-n_par831_ssiself_1990_7
			n_par831_ssiself_1991_1-n_par831_ssiself_1991_7
			n_par831_ssiself_1992_1-n_par831_ssiself_1992_7
			n_par831_ssiself_1993_1-n_par831_ssiself_1993_7
			n_par831_ssiself_1994_1-n_par831_ssiself_1994_7
			n_par831_ssiself_1995_1-n_par831_ssiself_1995_7
			n_par831_ssiself_1996_1-n_par831_ssiself_1996_7
			n_par831_ssiself_1997_1-n_par831_ssiself_1997_7
			n_par831_ssiself_1998_1-n_par831_ssiself_1998_7
			n_par831_ssiself_1999_1-n_par831_ssiself_1999_7
			n_par831_ssiself_2000_1-n_par831_ssiself_2000_7
			n_par831_ssiself_2001_1-n_par831_ssiself_2001_7
			n_par831_ssiself_2002_1-n_par831_ssiself_2002_7
			n_par831_ssiself_2003_1-n_par831_ssiself_2003_7
			n_par831_ssiself_2004_1-n_par831_ssiself_2004_7
			n_par831_ssiself_2005_1-n_par831_ssiself_2005_7
			n_par831_ssiself_2006_1-n_par831_ssiself_2006_7
			n_par831_ssiself_2007_1-n_par831_ssiself_2007_7
			n_par831_ssiself_2008_1-n_par831_ssiself_2008_7
			n_par831_ssiself_2009_1-n_par831_ssiself_2009_7
			n_par831_ssiself_2010_1-n_par831_ssiself_2010_7
			n_par831_ssiself_2011_1-n_par831_ssiself_2011_7
			;
			

	retain 	 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7
			
			inhh0206_1-inhh0206_7
			n_par831_diself_1985_1-n_par831_diself_1985_7
			n_par831_diself_1986_1-n_par831_diself_1986_7
			n_par831_diself_1987_1-n_par831_diself_1987_7
			n_par831_diself_1988_1-n_par831_diself_1988_7
			n_par831_diself_1989_1-n_par831_diself_1989_7
			n_par831_diself_1990_1-n_par831_diself_1990_7
			n_par831_diself_1991_1-n_par831_diself_1991_7
			n_par831_diself_1992_1-n_par831_diself_1992_7
			n_par831_diself_1993_1-n_par831_diself_1993_7
			n_par831_diself_1994_1-n_par831_diself_1994_7
			n_par831_diself_1995_1-n_par831_diself_1995_7
			n_par831_diself_1996_1-n_par831_diself_1996_7
			n_par831_diself_1997_1-n_par831_diself_1997_7
			n_par831_diself_1998_1-n_par831_diself_1998_7
			n_par831_diself_1999_1-n_par831_diself_1999_7
			n_par831_diself_2000_1-n_par831_diself_2000_7
			n_par831_diself_2001_1-n_par831_diself_2001_7
			n_par831_diself_2002_1-n_par831_diself_2002_7
			n_par831_diself_2003_1-n_par831_diself_2003_7
			n_par831_diself_2004_1-n_par831_diself_2004_7
			n_par831_diself_2005_1-n_par831_diself_2005_7
			n_par831_diself_2006_1-n_par831_diself_2006_7
			n_par831_diself_2007_1-n_par831_diself_2007_7
			n_par831_diself_2008_1-n_par831_diself_2008_7
			n_par831_diself_2009_1-n_par831_diself_2009_7
			n_par831_diself_2010_1-n_par831_diself_2010_7
			n_par831_diself_2011_1-n_par831_diself_2011_7

			n_par831_ssiself_1985_1-n_par831_ssiself_1985_7
			n_par831_ssiself_1986_1-n_par831_ssiself_1986_7
			n_par831_ssiself_1987_1-n_par831_ssiself_1987_7
			n_par831_ssiself_1988_1-n_par831_ssiself_1988_7
			n_par831_ssiself_1989_1-n_par831_ssiself_1989_7
			n_par831_ssiself_1990_1-n_par831_ssiself_1990_7
			n_par831_ssiself_1991_1-n_par831_ssiself_1991_7
			n_par831_ssiself_1992_1-n_par831_ssiself_1992_7
			n_par831_ssiself_1993_1-n_par831_ssiself_1993_7
			n_par831_ssiself_1994_1-n_par831_ssiself_1994_7
			n_par831_ssiself_1995_1-n_par831_ssiself_1995_7
			n_par831_ssiself_1996_1-n_par831_ssiself_1996_7
			n_par831_ssiself_1997_1-n_par831_ssiself_1997_7
			n_par831_ssiself_1998_1-n_par831_ssiself_1998_7
			n_par831_ssiself_1999_1-n_par831_ssiself_1999_7
			n_par831_ssiself_2000_1-n_par831_ssiself_2000_7
			n_par831_ssiself_2001_1-n_par831_ssiself_2001_7
			n_par831_ssiself_2002_1-n_par831_ssiself_2002_7
			n_par831_ssiself_2003_1-n_par831_ssiself_2003_7
			n_par831_ssiself_2004_1-n_par831_ssiself_2004_7
			n_par831_ssiself_2005_1-n_par831_ssiself_2005_7
			n_par831_ssiself_2006_1-n_par831_ssiself_2006_7
			n_par831_ssiself_2007_1-n_par831_ssiself_2007_7
			n_par831_ssiself_2008_1-n_par831_ssiself_2008_7
			n_par831_ssiself_2009_1-n_par831_ssiself_2009_7
			n_par831_ssiself_2010_1-n_par831_ssiself_2010_7
			n_par831_ssiself_2011_1-n_par831_ssiself_2011_7
			;

	array	assn(1:7) 			ssn1-ssn7 ; 
	array	atoa_ssr(1:7) $ 2	toa_ssr1-toa_ssr7 ;
	array	amft_ssr(1:7) $ 2	mft_ssr1-mft_ssr7;
	array	adob_ssr(1:7)		dob_ssr1-dob_ssr7;
	array	adobyy_ssr(1:7)		dobyy_ssr1-dobyy_ssr7; 
	array	adod_ssr(1:7)		dod_ssr1-dod_ssr7 ;
	array	asex_ssr(1:7) $ 2	sex_ssr1-sex_ssr7;

	array 	ainhh0206(1:7)				inhh0206_1-inhh0206_7;
	array 	apar831_diself_1985(1:7) 	n_par831_diself_1985_1-n_par831_diself_1985_7;
	array 	apar831_diself_1986(1:7) 	n_par831_diself_1986_1-n_par831_diself_1986_7;
	array 	apar831_diself_1987(1:7) 	n_par831_diself_1987_1-n_par831_diself_1987_7;
	array 	apar831_diself_1988(1:7) 	n_par831_diself_1988_1-n_par831_diself_1988_7;
	array 	apar831_diself_1989(1:7) 	n_par831_diself_1989_1-n_par831_diself_1989_7;
	array 	apar831_diself_1990(1:7) 	n_par831_diself_1990_1-n_par831_diself_1990_7;
	array 	apar831_diself_1991(1:7) 	n_par831_diself_1991_1-n_par831_diself_1991_7;
	array 	apar831_diself_1992(1:7) 	n_par831_diself_1992_1-n_par831_diself_1992_7;
	array 	apar831_diself_1993(1:7) 	n_par831_diself_1993_1-n_par831_diself_1993_7;
	array 	apar831_diself_1994(1:7) 	n_par831_diself_1994_1-n_par831_diself_1994_7;
	array 	apar831_diself_1995(1:7) 	n_par831_diself_1995_1-n_par831_diself_1995_7;
	array 	apar831_diself_1996(1:7) 	n_par831_diself_1996_1-n_par831_diself_1996_7;
	array 	apar831_diself_1997(1:7) 	n_par831_diself_1997_1-n_par831_diself_1997_7;
	array 	apar831_diself_1998(1:7) 	n_par831_diself_1998_1-n_par831_diself_1998_7;
	array 	apar831_diself_1999(1:7) 	n_par831_diself_1999_1-n_par831_diself_1999_7;
	array 	apar831_diself_2000(1:7) 	n_par831_diself_2000_1-n_par831_diself_2000_7;
	array 	apar831_diself_2001(1:7) 	n_par831_diself_2001_1-n_par831_diself_2001_7;
	array 	apar831_diself_2002(1:7) 	n_par831_diself_2002_1-n_par831_diself_2002_7;
	array 	apar831_diself_2003(1:7) 	n_par831_diself_2003_1-n_par831_diself_2003_7;
	array 	apar831_diself_2004(1:7) 	n_par831_diself_2004_1-n_par831_diself_2004_7;
	array 	apar831_diself_2005(1:7) 	n_par831_diself_2005_1-n_par831_diself_2005_7;
	array 	apar831_diself_2006(1:7) 	n_par831_diself_2006_1-n_par831_diself_2006_7;
	array 	apar831_diself_2007(1:7) 	n_par831_diself_2007_1-n_par831_diself_2007_7;
	array 	apar831_diself_2008(1:7) 	n_par831_diself_2008_1-n_par831_diself_2008_7;
	array 	apar831_diself_2009(1:7) 	n_par831_diself_2009_1-n_par831_diself_2009_7;
	array 	apar831_diself_2010(1:7) 	n_par831_diself_2010_1-n_par831_diself_2010_7;
	array 	apar831_diself_2011(1:7) 	n_par831_diself_2011_1-n_par831_diself_2011_7;

	array 	apar831_ssiself_1985(1:7) 	n_par831_ssiself_1985_1-n_par831_ssiself_1985_7;
	array 	apar831_ssiself_1986(1:7) 	n_par831_ssiself_1986_1-n_par831_ssiself_1986_7;
	array 	apar831_ssiself_1987(1:7) 	n_par831_ssiself_1987_1-n_par831_ssiself_1987_7;
	array 	apar831_ssiself_1988(1:7) 	n_par831_ssiself_1988_1-n_par831_ssiself_1988_7;
	array 	apar831_ssiself_1989(1:7) 	n_par831_ssiself_1989_1-n_par831_ssiself_1989_7;
	array 	apar831_ssiself_1990(1:7) 	n_par831_ssiself_1990_1-n_par831_ssiself_1990_7;
	array 	apar831_ssiself_1991(1:7) 	n_par831_ssiself_1991_1-n_par831_ssiself_1991_7;
	array 	apar831_ssiself_1992(1:7) 	n_par831_ssiself_1992_1-n_par831_ssiself_1992_7;
	array 	apar831_ssiself_1993(1:7) 	n_par831_ssiself_1993_1-n_par831_ssiself_1993_7;
	array 	apar831_ssiself_1994(1:7) 	n_par831_ssiself_1994_1-n_par831_ssiself_1994_7;
	array 	apar831_ssiself_1995(1:7) 	n_par831_ssiself_1995_1-n_par831_ssiself_1995_7;
	array 	apar831_ssiself_1996(1:7) 	n_par831_ssiself_1996_1-n_par831_ssiself_1996_7;
	array 	apar831_ssiself_1997(1:7) 	n_par831_ssiself_1997_1-n_par831_ssiself_1997_7;
	array 	apar831_ssiself_1998(1:7) 	n_par831_ssiself_1998_1-n_par831_ssiself_1998_7;
	array 	apar831_ssiself_1999(1:7) 	n_par831_ssiself_1999_1-n_par831_ssiself_1999_7;
	array 	apar831_ssiself_2000(1:7) 	n_par831_ssiself_2000_1-n_par831_ssiself_2000_7;
	array 	apar831_ssiself_2001(1:7) 	n_par831_ssiself_2001_1-n_par831_ssiself_2001_7;
	array 	apar831_ssiself_2002(1:7) 	n_par831_ssiself_2002_1-n_par831_ssiself_2002_7;
	array 	apar831_ssiself_2003(1:7) 	n_par831_ssiself_2003_1-n_par831_ssiself_2003_7;
	array 	apar831_ssiself_2004(1:7) 	n_par831_ssiself_2004_1-n_par831_ssiself_2004_7;
	array 	apar831_ssiself_2005(1:7) 	n_par831_ssiself_2005_1-n_par831_ssiself_2005_7;
	array 	apar831_ssiself_2006(1:7) 	n_par831_ssiself_2006_1-n_par831_ssiself_2006_7;
	array 	apar831_ssiself_2007(1:7) 	n_par831_ssiself_2007_1-n_par831_ssiself_2007_7;
	array 	apar831_ssiself_2008(1:7) 	n_par831_ssiself_2008_1-n_par831_ssiself_2008_7;
	array 	apar831_ssiself_2009(1:7) 	n_par831_ssiself_2009_1-n_par831_ssiself_2009_7;
	array 	apar831_ssiself_2010(1:7) 	n_par831_ssiself_2010_1-n_par831_ssiself_2010_7;
	array 	apar831_ssiself_2011(1:7) 	n_par831_ssiself_2011_1-n_par831_ssiself_2011_7;

	if first.hun then
	do;
		do i=1 to 7;
			assn(i) 		=.;	
			atoa_ssr(i)		="";
			amft_ssr(i)		="";	
			adob_ssr(i)		=.;	
			adobyy_ssr(i)	=.;		
			adod_ssr(i)		=.;	
			asex_ssr(i)		="";

			ainhh0206(i)		=.;
			apar831_diself_1985(i)	=.;
			apar831_diself_1986(i)	=.;
			apar831_diself_1987(i)	=.;
			apar831_diself_1988(i)	=.;
			apar831_diself_1989(i)	=.;
			apar831_diself_1990(i)	=.;
			apar831_diself_1991(i)	=.;
			apar831_diself_1992(i)	=.;
			apar831_diself_1993(i)	=.;
			apar831_diself_1994(i)	=.;
			apar831_diself_1995(i)	=.;
			apar831_diself_1996(i)	=.;
			apar831_diself_1997(i)	=.;
			apar831_diself_1998(i)	=.;
			apar831_diself_1999(i)	=.;
			apar831_diself_2000(i)	=.;
			apar831_diself_2001(i)	=.;
			apar831_diself_2002(i)	=.;
			apar831_diself_2003(i)	=.;
			apar831_diself_2004(i)	=.;
			apar831_diself_2005(i)	=.;
			apar831_diself_2006(i)	=.;
			apar831_diself_2007(i)	=.;
			apar831_diself_2008(i)	=.;
			apar831_diself_2009(i)	=.;
			apar831_diself_2010(i)	=.;
			apar831_diself_2011(i)	=.;

			apar831_ssiself_1985(i)	=.;
			apar831_ssiself_1986(i)	=.;
			apar831_ssiself_1987(i)	=.;
			apar831_ssiself_1988(i)	=.;
			apar831_ssiself_1989(i)	=.;
			apar831_ssiself_1990(i)	=.;
			apar831_ssiself_1991(i)	=.;
			apar831_ssiself_1992(i)	=.;
			apar831_ssiself_1993(i)	=.;
			apar831_ssiself_1994(i)	=.;
			apar831_ssiself_1995(i)	=.;
			apar831_ssiself_1996(i)	=.;
			apar831_ssiself_1997(i)	=.;
			apar831_ssiself_1998(i)	=.;
			apar831_ssiself_1999(i)	=.;
			apar831_ssiself_2000(i)	=.;
			apar831_ssiself_2001(i)	=.;
			apar831_ssiself_2002(i)	=.;
			apar831_ssiself_2003(i)	=.;
			apar831_ssiself_2004(i)	=.;
			apar831_ssiself_2005(i)	=.;
			apar831_ssiself_2006(i)	=.;
			apar831_ssiself_2007(i)	=.;
			apar831_ssiself_2008(i)	=.;
			apar831_ssiself_2009(i)	=.;
			apar831_ssiself_2010(i)	=.;
			apar831_ssiself_2011(i)	=.;

		end;
	end;

	assn(par_id) 		= ssn ;	
	atoa_ssr(par_id)	= toa_ssr ;
	amft_ssr(par_id)	= mft_ssr ;	
	adob_ssr(par_id)	= dob_ssr ;	
	adobyy_ssr(par_id)	= dobyy_ssr ;		
	adod_ssr(par_id)	= dod_ssr ;	
	asex_ssr(par_id)	= sex_ssr;
	
	ainhh0206(par_id)			= inhh0206;
	apar831_diself_1985(par_id)	= n_par831_diself_1985;
	apar831_diself_1986(par_id)	= n_par831_diself_1986;
	apar831_diself_1987(par_id)	= n_par831_diself_1987;
	apar831_diself_1988(par_id)	= n_par831_diself_1988;
	apar831_diself_1989(par_id)	= n_par831_diself_1989;
	apar831_diself_1990(par_id)	= n_par831_diself_1990;
	apar831_diself_1991(par_id)	= n_par831_diself_1991;
	apar831_diself_1992(par_id)	= n_par831_diself_1992;
	apar831_diself_1993(par_id)	= n_par831_diself_1993;
	apar831_diself_1994(par_id)	= n_par831_diself_1994;
	apar831_diself_1995(par_id)	= n_par831_diself_1995;
	apar831_diself_1996(par_id)	= n_par831_diself_1996;
	apar831_diself_1997(par_id)	= n_par831_diself_1997;
	apar831_diself_1998(par_id)	= n_par831_diself_1998;
	apar831_diself_1999(par_id)	= n_par831_diself_1999;
	apar831_diself_2000(par_id)	= n_par831_diself_2000;
	apar831_diself_2001(par_id)	= n_par831_diself_2001;
	apar831_diself_2002(par_id)	= n_par831_diself_2002;
	apar831_diself_2003(par_id)	= n_par831_diself_2003;
	apar831_diself_2004(par_id)	= n_par831_diself_2004;
	apar831_diself_2005(par_id)	= n_par831_diself_2005;
	apar831_diself_2006(par_id)	= n_par831_diself_2006;
	apar831_diself_2007(par_id)	= n_par831_diself_2007;
	apar831_diself_2008(par_id)	= n_par831_diself_2008;
	apar831_diself_2009(par_id)	= n_par831_diself_2009;
	apar831_diself_2010(par_id)	= n_par831_diself_2010;
	apar831_diself_2011(par_id)	= n_par831_diself_2011;

	apar831_ssiself_1985(par_id)	= n_par831_ssiself_1985;
	apar831_ssiself_1986(par_id)	= n_par831_ssiself_1986;
	apar831_ssiself_1987(par_id)	= n_par831_ssiself_1987;
	apar831_ssiself_1988(par_id)	= n_par831_ssiself_1988;
	apar831_ssiself_1989(par_id)	= n_par831_ssiself_1989;
	apar831_ssiself_1990(par_id)	= n_par831_ssiself_1990;
	apar831_ssiself_1991(par_id)	= n_par831_ssiself_1991;
	apar831_ssiself_1992(par_id)	= n_par831_ssiself_1992;
	apar831_ssiself_1993(par_id)	= n_par831_ssiself_1993;
	apar831_ssiself_1994(par_id)	= n_par831_ssiself_1994;
	apar831_ssiself_1995(par_id)	= n_par831_ssiself_1995;
	apar831_ssiself_1996(par_id)	= n_par831_ssiself_1996;
	apar831_ssiself_1997(par_id)	= n_par831_ssiself_1997;
	apar831_ssiself_1998(par_id)	= n_par831_ssiself_1998;
	apar831_ssiself_1999(par_id)	= n_par831_ssiself_1999;
	apar831_ssiself_2000(par_id)	= n_par831_ssiself_2000;
	apar831_ssiself_2001(par_id)	= n_par831_ssiself_2001;
	apar831_ssiself_2002(par_id)	= n_par831_ssiself_2002;
	apar831_ssiself_2003(par_id)	= n_par831_ssiself_2003;
	apar831_ssiself_2004(par_id)	= n_par831_ssiself_2004;
	apar831_ssiself_2005(par_id)	= n_par831_ssiself_2005;
	apar831_ssiself_2006(par_id)	= n_par831_ssiself_2006;
	apar831_ssiself_2007(par_id)	= n_par831_ssiself_2007;
	apar831_ssiself_2008(par_id)	= n_par831_ssiself_2008;
	apar831_ssiself_2009(par_id)	= n_par831_ssiself_2009;
	apar831_ssiself_2010(par_id)	= n_par831_ssiself_2010;
	apar831_ssiself_2011(par_id)	= n_par831_ssiself_2011;

	if last.hun then output;

run;

data manasi.par_831_hunmerge_wide;
	set manasi.par_831_hunmerge_wide;

	* Create macro for summing over all 831 variables ;
	%macro sum831(year);
		n_par831di_&year.=SUM(OF n_par831_diself_&year._:);
		n_par831ssi_&year.=SUM(OF n_par831_ssiself_&year._:);

		n_par831di0206_&year.=0;
		if inhh0206_1=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._1;
		if inhh0206_2=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._2;
		if inhh0206_3=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._3;
		if inhh0206_4=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._4;
		if inhh0206_5=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._5;
		if inhh0206_6=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._6;
		if inhh0206_7=1 then n_par831di0206_&year.=n_par831di0206_&year.+n_par831_diself_&year._7;

		n_par831ssi0206_&year.=0;
		if inhh0206_1=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._1;
		if inhh0206_2=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._2;
		if inhh0206_3=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._3;
		if inhh0206_4=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._4;
		if inhh0206_5=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._5;
		if inhh0206_6=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._6;
		if inhh0206_7=1 then n_par831ssi0206_&year.=n_par831ssi0206_&year.+n_par831_ssiself_&year._7;
	%mend sum831;

	%sum831(1985);
	%sum831(1986);
	%sum831(1987);
	%sum831(1988);
	%sum831(1989);
	%sum831(1990);
	%sum831(1991);
	%sum831(1992);
	%sum831(1993);
	%sum831(1994);
	%sum831(1995);
	%sum831(1996);
	%sum831(1997);
	%sum831(1998);
	%sum831(1999);
	%sum831(2000);
	%sum831(2001);
	%sum831(2002);
	%sum831(2003);
	%sum831(2004);
	%sum831(2005);
	%sum831(2006);
	%sum831(2007);
	%sum831(2008);
	%sum831(2009);
	%sum831(2010);
	%sum831(2011);

	%macro dropvar(var);
		drop &var.3-&var.7;
	%mend dropvar;

	%dropvar(ssn);
	%dropvar(toa_ssr);
	%dropvar(mft_ssr);
	%dropvar(dob_ssr);
	%dropvar(dobyy_ssr);
	%dropvar(dod_ssr);
	%dropvar(sex_ssr);

	%macro drop831(year);
		drop n_par831_diself_&year._1-n_par831_diself_&year._7;
		drop n_par831_ssiself_&year._1-n_par831_ssiself_&year._7;
	%mend drop831;

	%drop831(1985);
	%drop831(1986);
	%drop831(1987);
	%drop831(1988);
	%drop831(1989);
	%drop831(1990);
	%drop831(1991);
	%drop831(1992);
	%drop831(1993);
	%drop831(1994);
	%drop831(1995);
	%drop831(1996);
	%drop831(1997);
	%drop831(1998);
	%drop831(1999);
	%drop831(2000);
	%drop831(2001);
	%drop831(2002);
	%drop831(2003);
	%drop831(2004);
	%drop831(2005);
	%drop831(2006);
	%drop831(2007);
	%drop831(2008);
	%drop831(2009);
	%drop831(2010);
	%drop831(2011);

	%macro rename(var,no);
		rename &var.&no.=par&no._&var.;
	%mend rename;

	%rename(ssn,1);
	%rename(ssn,2);
	%rename(toa_ssr,1);
	%rename(toa_ssr,2);
	%rename(mft_ssr,1);
	%rename(mft_ssr,2);
	%rename(dob_ssr,1);
	%rename(dob_ssr,2);
	%rename(dobyy_ssr,1);
	%rename(dobyy_ssr,2);
	%rename(dod_ssr,1);
	%rename(dod_ssr,2);
	%rename(sex_ssr,1);
	%rename(sex_ssr,2);

run;
